<!DOCTYPE HTML>
<html>
   <head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<title>知果汇</title>
		<link href="_CSS_/bootstrap.min.css" rel="stylesheet">
		<link href="_CSS_/simple-line-icons.css" rel="stylesheet">
		<link href="_CSS_/font-awesome.min.css" rel="stylesheet">
		<link href="_CSS_/jasny-bootstrap.min.css" rel="stylesheet">
		<link rel="stylesheet" href="_CSS_/nanoscroller.css">
		<link href="_CSS_/style.css" rel="stylesheet">
		<link rel="stylesheet" type="text/css" href="_CSS_/jquery-ui.css">
		<!--[if lt IE 9]>
		  <script src="_JS_/html5shiv.min.js"></script>
		  <script src="_JS_/respond.min.js"></script>
		<![endif]-->
		<style type="text/css">
		    body{background-color: #ffffff;}
			.row{margin-left: 0px;margin-right: 0px;}
			.radio-box{display:inline-block;width: 64px;}
			.formControls{padding-right:50px; position: relative;}
			.textarea {height: 100px;resize: none;font-size: 14px;padding: 4px;}
            .textarea-numberbar {position: absolute;right: 70px;bottom: 5px;z-index: 1;margin-bottom: 0;}
		</style>
    </head>
	<body>
	<article class="page-container">
		<form class="form form-horizontal" id="form-admin-add">
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3">政策类别：</label>
				<div class="formControls col-xs-8 col-sm-9"> <span class="select-box" style="width:150px;">
					<select id="newsrole" class="select" name="newsrole" size="1">
						<option value="1">知识产权资助</option>
						<option value="2">知识产权奖励</option>
						<option value="3">维权奖励</option>
						<option value="4">企业奖励</option>
						<option value="5">项目奖励</option>
						<option value="6">金融补贴</option>
						<option value="7">知识产权运用奖励</option>
						<option value="8">知识产权保护奖励（贯标、商标注册）</option>
					</select>
					</span> </div>
			</div>
			<div id="types" class="row cl hide">
				<label class="form-label col-xs-4 col-sm-3">政策子类别：</label>
				<div class="formControls col-xs-8 col-sm-9"> <span class="select-box" style="width:150px;">
					<select id="type" class="select" name="type" size="1">
						
					</select>
					</span> </div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3">城市：</label>
				<div class="formControls col-xs-8 col-sm-9"> <span class="select-box" style="width:150px;">
					<select id="area" class="select" name="area" size="1">
						<option value="武汉市">武汉市</option>
						<option value="黄石市">黄石市</option>
						<option value="十堰市">十堰市</option>
						<option value="宜昌市">宜昌市</option>
						<option value="襄阳市">襄阳市</option>
						<option value="鄂州市">鄂州市</option>
						<option value="荆门市">荆门市</option>
						<option value="孝感市">孝感市</option>
						<option value="荆州市">荆州市</option>
						<option value="黄冈市">黄冈市</option>
						<option value="咸宁市">咸宁市</option>
						<option value="随州市">随州市</option>
						<option value="恩施土家族苗族自治州">恩施土家族苗族自治州</option>
						<option value="仙桃市">仙桃市</option>
						<option value="潜江市">潜江市</option>
						<option value="天门市">天门市</option>
						<option value="神农架林区">神农架林区</option>
					</select>
					</span> </div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3">区镇：</label>
				<div class="formControls col-xs-8 col-sm-9"> <span class="select-box" style="width:150px;">
					<select id="city" class="select" name="city" size="1">
					<option value='0'>全部</option>
					</select>
					</span> </div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3">文件编号：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<input type="text" id="paper" class="input-text" value="" placeholder="" id="number" name="paper">
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3">有效时间：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<input type="text" id="news_title" class="input-text" value="" placeholder="" id="stime" name="stime">
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3">政策内容：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<textarea id="news_adstract" name="content" cols="" rows="" class="textarea"  placeholder="请输入政策内容...500个字符以内" dragonfly="true" onKeyUp="textarealength(this,500)"></textarea>
					<p class="textarea-numberbar"><em class="textarea-length">0</em>/500</p>
				</div>
			</div>
			<div class="row cl">
				<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
					<input class="btn btn-primary radius" type="button" value="&nbsp;&nbsp;保存并发布&nbsp;&nbsp;">
					<input class="btn btn-warning radius" type="button" value="&nbsp;&nbsp;保存为草稿&nbsp;&nbsp;">
					<input class="btn btn-default radius" style="color: #ffffff;background-color: #a0a0a0;" type="button" value="&nbsp;&nbsp;取消&nbsp;&nbsp;">
				</div>
			</div>
		</form>
	</article>

<!--_footer 作为公共模版分离出去-->
    <script src="_JS_/jquery.min.js"></script>
	<!-- <script src="_JS_/jquery.form.js"></script> -->
	<script src="_JS_/jquery.base64.js"></script>
    <script src="_JS_/jquery.cookie.js"></script>
    <script src="_JS_/bootstrap.min.js"></script>
    <script src="_JS_/jasny-bootstrap.min.js"></script>
    <script src="_JS_/jquery.slimscroll.min.js"></script>
    <script src="_JS_/jquery.nanoscroller.min.js"></script>
    <script src="_JS_/metismenu.min.js"></script>
    <script src="_JS_/float-custom.js"></script>
    <script type="text/javascript" src="_JS_/layer/layer.js"></script>
    <script type="text/javascript" src="_JS_/jquery.validation/1.14.0/jquery.validate.min.js"></script>
    <script type="text/javascript" src="_JS_/jquery.validation/1.14.0/validate-methods.js"></script>
    <script type="text/javascript" src="_JS_/jquery.validation/1.14.0/messages_zh.min.js"></script>   

<script type="text/javascript">
var url=window.location.href;
    id = url.split("#")[1];
    user_id = url.split("#")[2];

	$(function(){
        
       

	    //新闻详情加载
	    $.ajax({
	        type: "get",
	        url: "{:url('api/policy/policy_detail')}",
	        dataType: 'jsonp',
			jsonp:'callback',
	        data:{'id':id},
	        success: function (msg) {
	            if(msg.code == 200){
                    $('#area').val(msg.data.area1);
				    $('#newsrole').val(msg.data.pid);
					$('#paper').val(msg.data.paper);
				   $('#news_title').val(msg.data.stime);
				   $('#news_adstract').val(msg.data.content);
					get_type(msg.data.pid,msg.data.sort);
					get_city(msg.data.area1,msg.data.area2);
						    
	            }
	            if(msg.code==1000){
	                layer.msg(msg.message,{icon:5,time:2000});
	            }
	        }
	    });

	});

	$('#newsrole').on('change',function(){
		var pid=$(this).val();		
		get_type(pid);
	})
	function get_type(pid,index){
		$.ajax({ 
			type: "get", 
			url: "{:url('Api/policy/type')}",
			dataType: 'jsonp',
			jsonp:'callback',
			data: {'pid':pid},
			success: function (msg) {
				
				if(msg.code == 200){
					$("#types").removeClass('hide');
					$("#type").html('');
					var html='';
					for(var i=0;i<msg.data.length;i++){
						 html+='<option value="'+msg.data[i].t_id+'"';
						if(index==msg.data[i].t_id){
							html+='selected="selected">';
						}else{
							html+='>';
						}
						html+=msg.data[i].name+'</option>';
						
					}
					$("#type").html(html);
				}
				if(msg.code==1000){
					$("#types").addClass('hide');
					$("#type").html('');
					//layer.msg(msg.message,{icon:5,time:1000});
				}
				
			}
		});
	}
	$('#area').on('change',function(){
		var pid=$(this).val();
		get_city(pid);
	})
	function get_city(pid,index){
	
		$.ajax({ 
			type: "get", 
			url: "{:url('Api/policy/area_name')}",
			dataType: 'jsonp',
			jsonp:'callback',
			data: {'pid':pid},
			success: function (msg) {
				if(msg.code == 200){
					$("#city").parent().removeClass('hide');
					$("#city").html('');
					var html='<option value="0">全部</option>';
					for(var i=0;i<msg.data.length;i++){
						 html+='<option value="'+msg.data[i].name+'"';
						if(index==msg.data[i].name){
							html+='selected="selected">';
						}else{
							html+='>';
						}
						html+=msg.data[i].name+'</option>';
						
					}
					$("#city").html(html);
				}
				if(msg.code==1000){
					$("#city").html('<option value="0">全部</option>');
					
					//layer.msg(msg.message,{icon:5,time:1000});
				}
			}
		});
	}
	/*textarea 字数限制*/
	function textarealength(obj,maxlength){
		var v = $(obj).val();
		var l = v.length;
		if( l > maxlength){
			v = v.substring(0,maxlength);
			$(obj).val(v);
		}
		$(obj).parent().find(".textarea-length").text(v.length);
	}
	/*发布按钮*/
	$('.btn-primary').on('click',function(){
		button(2);
	});
	/*保存按钮*/
	$('.btn-warning').on('click',function(){
		button(1);
	});
	/*取消按钮*/
	$('.btn-default').on('click',function(){
		var index = parent.layer.getFrameIndex(window.name);
		parent.layer.close(index);
	});
	function button(status){
	
		 var  sort=$('#newsrole').val();
	   var  type=$('#type').val();
	   var  area=$('#area').val();
	   var  city=$('#city').val();
	   var  paper=$('#paper').val();
	   var  news_title=$('#news_title').val();
	   var  news_adstract=$('#news_adstract').val();
	    uid=user_id;
	if(sort!=""&&area!=""&&city!=""&&news_adstract!=""){

		$.ajax({ 
			url:"{:url('Api/policy/policy_edit')}",
			type: "post",
			dataType:"json",
			data:{
			'id':id,
				"content":news_adstract,
				"status":status,
				"sort":sort,
				"type":type,
				"area":area,
				"city":city,
				"paper":paper,
				"news_title":news_title,
				"uid":uid
			},
				success: function(msg){
					if(msg.code == 200){
		            	var index = parent.layer.getFrameIndex(window.name);
						parent.layer.close(index);
						parent.window.location.reload();
		            }
		            if(msg.code==1000){
		                layer.msg(msg.message,{icon:5,time:1000});
		            }
				},
				error: function(){
					layer.closeAll();
					layer.msg('网络错误');
				}
			});
	    }else{
	    	layer.msg('请完善发布内容!',{icon:0,time:1000})
	    }
	}

</script>
</body>
</html>